<!-- build time:Tue Jul 21 2020 12:41:22 GMT+0800 (GMT+08:00) --><!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=2"><meta name="theme-color" content="#222"><meta name="generator" content="Hexo 4.2.0"><link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png"><link rel="icon" type="image/png" sizes="32x32" href="/img/blog_favicon/favicon-32x32-next.png"><link rel="icon" type="image/png" sizes="16x16" href="/img/blog_favicon/favicon-16x16-next.png"><link rel="mask-icon" href="/images/logo.svg" color="#222"><meta name="baidu-site-verification" content="r15J5zOS2KI43yBS"><link rel="stylesheet" href="/css/main.css"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"><link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/themes/blue/pace-theme-minimal.min.css"><script src="//cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/pace.min.js"></script><script id="hexo-configurations">var NexT=window.NexT||{},CONFIG={hostname:new URL("http://www.zhengjiaao.cn").hostname,root:"/",scheme:"Muse",version:"7.6.0",exturl:!1,sidebar:{position:"left",display:"post",padding:18,offset:12,onmobile:!1},copycode:{enable:!0,show_result:!0,style:null},back2top:{enable:!0,sidebar:!1,scrollpercent:!0},bookmark:{enable:!0,color:"#222",save:"auto"},fancybox:!0,mediumzoom:!1,lazyload:!1,pangu:!1,comments:{style:"tabs",active:"valine",storage:!0,lazyload:!1,nav:null,activeClass:"valine"},algolia:{appID:"",apiKey:"",indexName:"",hits:{per_page:10},labels:{input_placeholder:"Search for Posts",hits_empty:"We didn't find any results for the search: ${query}",hits_stats:"${hits} results found in ${time} ms"}},localsearch:{enable:!0,trigger:"auto",top_n_per_article:1,unescape:!1,preload:!1},path:"search.xml",motion:{enable:!0,async:!1,transition:{post_block:"fadeIn",post_header:"slideDownIn",post_body:"slideDownIn",coll_header:"slideLeftIn",sidebar:"slideUpIn"}}}</script><meta property="og:type" content="article"><meta property="og:title" content="Windwos Elasticsearch"><meta property="og:url" content="http://www.zhengjiaao.cn/posts/2791142199.html"><meta property="og:site_name" content="宇宙小神特别萌"><meta property="og:locale" content="zh_CN"><meta property="article:published_time" content="2020-07-20T10:50:51.000Z"><meta property="article:modified_time" content="2020-07-20T10:54:34.129Z"><meta property="article:author" content="宇宙小神特别萌"><meta property="article:tag" content="Elasticsearch"><meta name="twitter:card" content="summary"><link rel="canonical" href="http://www.zhengjiaao.cn/posts/2791142199.html"><script id="page-configurations">CONFIG.page={sidebar:"",isHome:!1,isPost:!0}</script><title>Windwos Elasticsearch | 宇宙小神特别萌</title><noscript><style>.sidebar-inner,.use-motion .brand,.use-motion .collection-header,.use-motion .comments,.use-motion .menu-item,.use-motion .pagination,.use-motion .post-block,.use-motion .post-body,.use-motion .post-header{opacity:initial}.use-motion .site-subtitle,.use-motion .site-title{opacity:initial;top:initial}.use-motion .logo-line-before i{left:initial}.use-motion .logo-line-after i{right:initial}</style></noscript><link rel="alternate" href="/atom.xml" title="宇宙小神特别萌" type="application/atom+xml"></head><body itemscope itemtype="http://schema.org/WebPage"><div class="container use-motion"><div class="headband"></div><header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="header-inner"><div class="site-brand-container"><div class="site-meta custom-logo"><div class="site-meta-headline"><a><img class="custom-logo-image" src="/img/blog_favicon/favicon-32x32-next.png" alt="宇宙小神特别萌"></a></div><div><a href="/" class="brand" rel="start"><span class="logo-line-before"><i></i></span> <span class="site-title">宇宙小神特别萌</span> <span class="logo-line-after"><i></i></span></a></div><p class="site-subtitle">ZhengJa</p></div><div class="site-nav-toggle"><div class="toggle" aria-label="切换导航栏"><span class="toggle-line toggle-line-first"></span> <span class="toggle-line toggle-line-middle"></span> <span class="toggle-line toggle-line-last"></span></div></div></div><nav class="site-nav"><ul id="menu" class="menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签<span class="badge">27</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档<span class="badge">116</span></a></li><li class="menu-item menu-item-sitemap"><a href="/sitemap.xml" rel="section"><i class="fa fa-fw fa-sitemap"></i>站点地图</a></li><li class="menu-item menu-item-messageboard"><a href="/messageboard/" rel="section"><i class="fa fa-fw fa-address-book"></i>留言板</a></li><li class="menu-item menu-item-links"><a href="/links/" rel="section"><i class="fa fa-fw fa-user-plus"></i>友链</a></li><li class="menu-item menu-item-shuoshuo"><a href="/shuoshuo/" rel="section"><i class="fa fa-fw fa-file-text-o"></i>说说</a></li><li class="menu-item menu-item-search"><a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索</a></li></ul></nav><div class="site-search"><div class="popup search-popup"><div class="search-header"><span class="search-icon"><i class="fa fa-search"></i></span><div class="search-input-container"><input autocomplete="off" autocorrect="off" autocapitalize="none" placeholder="搜索..." spellcheck="false" type="text" id="search-input"></div><span class="popup-btn-close"><i class="fa fa-times-circle"></i></span></div><div id="search-result"></div></div><div class="search-pop-overlay"></div></div></div></header><div class="back-to-top"><i class="fa fa-arrow-up"></i> <span>0%</span></div><div class="reading-progress-bar"></div><a role="button" class="book-mark-link book-mark-link-fixed"></a> <a href="https://github.com/zhengjiaao" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin:130px 106px" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><main class="main"><div class="main-inner"><div class="content-wrap"><div class="content"><div class="posts-expand"><article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN"><link itemprop="mainEntityOfPage" href="http://www.zhengjiaao.cn/posts/2791142199.html"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="image" content="/my-images/avatar.gif"><meta itemprop="name" content="宇宙小神特别萌"><meta itemprop="description" content="人生就是一次幸运的旅行！"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="宇宙小神特别萌"></span><header class="post-header"><h1 class="post-title" itemprop="name headline">Windwos Elasticsearch</h1><div class="post-meta"><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-calendar-o"></i> </span><span class="post-meta-item-text">发表于</span> <time title="创建时间：2020-07-20 18:50:51 / 修改时间：18:54:34" itemprop="dateCreated datePublished" datetime="2020-07-20T18:50:51+08:00">2020-07-20</time> </span><span id="/posts/2791142199.html" class="post-meta-item leancloud_visitors" data-flag-title="Windwos Elasticsearch" title="热度"><span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="post-meta-item-text">热度：</span> <span class="leancloud-visitors-count"></span> <span>℃</span> </span><span class="post-meta-item" title="热度" id="busuanzi_container_page_pv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="post-meta-item-text">热度：</span> <span id="busuanzi_value_page_pv"></span> </span><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-comment-o"></i> </span><span class="post-meta-item-text">Valine：</span> <a title="valine" href="/posts/2791142199.html#comments" itemprop="discussionUrl"><span class="post-comments-count valine-comment-count" data-xid="/posts/2791142199.html" itemprop="commentCount"></span></a></span><br><span class="post-meta-item" title="本文字数"><span class="post-meta-item-icon"><i class="fa fa-file-word-o"></i> </span><span class="post-meta-item-text">本文字数：</span> <span>18k</span> </span><span class="post-meta-item" title="阅读时长"><span class="post-meta-item-icon"><i class="fa fa-clock-o"></i> </span><span class="post-meta-item-text">阅读时长 &asymp;</span> <span>16 分钟</span></span></div></header><div class="post-body" itemprop="articleBody"><meta name="referrer" content="no-referrer"><a id="more"></a><h4 id="Elasticsearch-基本介绍"><a href="#Elasticsearch-基本介绍" class="headerlink" title="Elasticsearch 基本介绍"></a>Elasticsearch 基本介绍</h4><p><a href="https://baike.baidu.com/item/全文搜索引擎" target="_blank" rel="noopener">全文搜索</a>属于最常见的需求，开源的 <a href="https://www.elastic.co/" target="_blank" rel="noopener">Elasticsearch</a> （以下简称 Elastic）是目前全文搜索引擎的首选。</p><p>Elasticsearch是一个开源的分布式、RESTful 风格的搜索和数据分析引擎，它的底层是开源库Apache Lucene。<br> Lucene 可以说是当下最先进、高性能、全功能的搜索引擎库——无论是开源还是私有，但它也仅仅只是一个库。为了充分发挥其功能，你需要使用 Java 并将 Lucene 直接集成到应用程序中。 更糟糕的是，您可能需要获得信息检索学位才能了解其工作原理，因为Lucene 非常复杂。</p><p>Elastic 的底层是开源库 <a href="https://lucene.apache.org/" target="_blank" rel="noopener">Lucene</a>。但是，你没法直接用 Lucene，必须自己写代码去调用它的接口。Elastic 是 Lucene 的封装，提供了 REST API 的操作接口，开箱即用。</p><p> 为了解决Lucene使用时的繁复性，于是Elasticsearch便应运而生。它使用 Java 编写，内部采用 Lucene 做索引与搜索，但是它的目标是使全文检索变得更简单，简单来说，就是对Lucene 做了一层封装，它提供了一套简单一致的 RESTful API 来帮助我们实现存储和检索。<br> 当然，Elasticsearch 不仅仅是 Lucene，并且也不仅仅只是一个全文搜索引擎。 它可以被下面这样准确地形容：</p><ul><li>一个分布式的实时文档存储，每个字段可以被索引与搜索</li><li>一个分布式实时分析搜索引擎</li><li>能胜任上百个服务节点的扩展，并支持 PB 级别的结构化或者非结构化数据</li><li>可以快速地储存、搜索和分析海量数据</li></ul><p>由于Elasticsearch的功能强大和使用简单，维基百科、卫报、Stack Overflow、GitHub等都纷纷采用它来做搜索。现在，Elasticsearch已成为全文搜索领域的主流软件之一。</p><p>Elastic 是java写的，需要 Java 的jdk环境，根据下方【版本手册】查看对应jdk版本。</p><p><strong>推荐华为镜像快速下载</strong>：<a href="https://mirrors.huaweicloud.com/elasticsearch/" target="_blank" rel="noopener">https://mirrors.huaweicloud.com/elasticsearch/</a></p><p><strong>官方选择下载</strong>：<a href="https://www.elastic.co/cn/downloads/past-releases/#elasticsearch" target="_blank" rel="noopener">https://www.elastic.co/cn/downloads/past-releases/#elasticsearch</a></p><p><strong>所有版本手册</strong>：<a href="https://www.elastic.co/guide/en/elasticsearch/reference/index.html" target="_blank" rel="noopener">https://www.elastic.co/guide/en/elasticsearch/reference/index.html</a></p><p><strong>客户端</strong>：<a href="https://www.elastic.co/guide/en/elasticsearch/client/index.html" target="_blank" rel="noopener">https://www.elastic.co/guide/en/elasticsearch/client/index.html</a></p><h4 id="Elasticsearch-6-8-5-单机安装"><a href="#Elasticsearch-6-8-5-单机安装" class="headerlink" title="Elasticsearch 6.8.5 单机安装"></a>Elasticsearch 6.8.5 单机安装</h4><p>环境要求：jdk1.8(最低)、Elasticsearch 6.8.5</p><p>系统：Windwows</p><p>下载：<a href="https://mirrors.huaweicloud.com/elasticsearch/6.8.5/elasticsearch-6.8.5.zip" target="_blank" rel="noopener">elasticsearch-6.8.5.zip</a> , <a href="https://www.elastic.co/guide/en/elasticsearch/reference/6.8/index.html" target="_blank" rel="noopener">参考手册-6.8</a></p><p>安装：解压，找到<code>bin\elasticsearch.bat</code>，双击运行</p><p>访问：<strong><a href="http://127.0.0.1:9200/" target="_blank" rel="noopener">http://127.0.0.1:9200/</a></strong></p><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"name"</span> : <span class="string">"i1_C38J"</span>,</span><br><span class="line">  <span class="attr">"cluster_name"</span> : <span class="string">"elasticsearch"</span>,</span><br><span class="line">  <span class="attr">"cluster_uuid"</span> : <span class="string">"_YG2A3LpSoOdh-wdLPOzlA"</span>,</span><br><span class="line">  <span class="attr">"version"</span> : &#123;</span><br><span class="line">    <span class="attr">"number"</span> : <span class="string">"6.8.5"</span>,</span><br><span class="line">    <span class="attr">"build_flavor"</span> : <span class="string">"default"</span>,</span><br><span class="line">    <span class="attr">"build_type"</span> : <span class="string">"zip"</span>,</span><br><span class="line">    <span class="attr">"build_hash"</span> : <span class="string">"78990e9"</span>,</span><br><span class="line">    <span class="attr">"build_date"</span> : <span class="string">"2019-11-13T20:04:24.100411Z"</span>,</span><br><span class="line">    <span class="attr">"build_snapshot"</span> : <span class="literal">false</span>,</span><br><span class="line">    <span class="attr">"lucene_version"</span> : <span class="string">"7.7.2"</span>,</span><br><span class="line">    <span class="attr">"minimum_wire_compatibility_version"</span> : <span class="string">"5.6.0"</span>,</span><br><span class="line">    <span class="attr">"minimum_index_compatibility_version"</span> : <span class="string">"5.0.0"</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">"tagline"</span> : <span class="string">"You Know, for Search"</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><blockquote><p>以上显示效果说明已经安装好Elasticsearch</p></blockquote><h4 id="kibana6-8-5-可视化工具"><a href="#kibana6-8-5-可视化工具" class="headerlink" title="kibana6.8.5 可视化工具"></a>kibana6.8.5 可视化工具</h4><blockquote><p>注意: kibana版本必须和Elasticsearch版本一致，否则会出现不可预料的错误。</p></blockquote><p>安装参考：<a href="https://www.elastic.co/guide/cn/kibana/current/windows.html" target="_blank" rel="noopener">https://www.elastic.co/guide/cn/kibana/current/windows.html</a></p><p>下载：<a href="https://mirrors.huaweicloud.com/kibana/6.8.5/kibana-6.8.5-windows-x86_64.zip" target="_blank" rel="noopener">kibana-6.8.5-windows-x86_64.zip)</a> 解压。</p><p>*<em>zip目录文件： *</em></p><p><code>.zip</code> 整个包是独立的。默认情况下，所有的文件和目录都在 <code>$KIBANA_HOME</code> — 解压包时创建的目录下。这是非常方便的，因为您不需要创建任何目录来使用 Kibana，卸载 Kibana 只需要简单的删除 <code>$KIBANA_HOME</code> 目录。但还是建议修改一下配置文件和数据目录，这样就不会删除重要数据。</p><table><thead><tr><th>类型</th><th>描述</th><th>默认位置</th><th>设置</th></tr></thead><tbody><tr><td><strong>home</strong></td><td>Kibana home 目录或 <code>$KIBANA_HOME</code> 。</td><td>解压包时创建的目录</td><td></td></tr><tr><td><strong>bin</strong></td><td>二进制脚本，包括 <code>kibana</code> 启动 Kibana 服务和 <code>kibana-plugin</code> 安装插件。</td><td><code>$KIBANA_HOME\bin</code></td><td></td></tr><tr><td><strong>config</strong></td><td>配置文件包括 <code>kibana.yml</code> 。</td><td><code>$KIBANA_HOME\config</code></td><td></td></tr><tr><td><strong>data</strong></td><td>Kibana 和其插件写入磁盘的数据文件位置。</td><td><code>$KIBANA_HOME\data</code></td><td></td></tr><tr><td><strong>optimize</strong></td><td>编译过的源码。某些管理操作(如，插件安装)导致运行时重新编译源码。</td><td><code>$KIBANA_HOME\optimize</code></td><td></td></tr><tr><td><strong>plugins</strong></td><td>插件文件位置。每一个插件都一个单独的二级目录。</td><td><code>$KIBANA_HOME\plugins</code></td><td></td></tr></tbody></table><p>配置系统环境变量：KIBANA_HOME=E:\Elasticsearch\kibana-6.8.5-windows-x86_64\bin</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"># 启动 kibana</span><br><span class="line">.\bin\kibana.bat</span><br><span class="line"># 日志：输出 log 到 STDOUT</span><br><span class="line"># Ctrl-C 停止 Kibana</span><br></pre></td></tr></table></figure><p>浏览器访问：<a href="http://localhost:5601" target="_blank" rel="noopener">http://localhost:5601</a> 安装成功。</p><p><strong>kibana 汉化</strong>:</p><p>从6.7版本开始，<code>Kibana</code>支持中文，无需再像之前那样下载汉化包，甚至自己进行翻译</p><p>打开config/kibana.yml，找到最后一行，去掉<code>#</code>，并将<code>&quot;en&quot;</code>改成<code>&quot;zh-CN&quot;</code></p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#i18n.locale: "en"</span></span><br><span class="line"><span class="attr">i18n.locale:</span> <span class="string">"zh-CN"</span></span><br></pre></td></tr></table></figure><p>*<em>重启kibana *</em></p><h4 id="elasticsearch-analysis-ik-分词器"><a href="#elasticsearch-analysis-ik-分词器" class="headerlink" title="elasticsearch-analysis-ik 分词器"></a>elasticsearch-analysis-ik 分词器</h4><p>参考连接：<a href="https://github.com/medcl/elasticsearch-analysis-ik" target="_blank" rel="noopener">https://github.com/medcl/elasticsearch-analysis-ik</a></p><p>IK version 和 ES version 要一致：</p><table><thead><tr><th>IK version</th><th>ES version</th></tr></thead><tbody><tr><td>master</td><td>7.x -&gt; master</td></tr><tr><td>6.x</td><td>6.x</td></tr></tbody></table><h1 id="Springboot-Elasticsearch-6-8-5"><a href="#Springboot-Elasticsearch-6-8-5" class="headerlink" title="Springboot  Elasticsearch 6.8.5"></a>Springboot Elasticsearch 6.8.5</h1><h2 id="一、选择版本"><a href="#一、选择版本" class="headerlink" title="一、选择版本"></a>一、选择版本</h2><h4 id="Spring-Data-Elasticsearch"><a href="#Spring-Data-Elasticsearch" class="headerlink" title="Spring Data Elasticsearch"></a>Spring Data Elasticsearch</h4><blockquote><p>参考：<a href="https://docs.spring.io/spring-data/elasticsearch/docs/3.2.0.RC3/reference/html/#preface.versions" target="_blank" rel="noopener">https://docs.spring.io/spring-data/elasticsearch/docs/3.2.0.RC3/reference/html/#preface.versions</a></p></blockquote><p>Spring Data Elasticsearch、Elasticsearch 对应版本</p><table><thead><tr><th>Spring Data Elasticsearch</th><th>Elasticsearch</th></tr></thead><tbody><tr><td>3.2.x</td><td>6.8.1</td></tr><tr><td>3.1.x</td><td>6.2.2</td></tr><tr><td>3.0.x</td><td>5.5.0</td></tr><tr><td>2.1.x</td><td>2.4.0</td></tr><tr><td>2.0.x</td><td>2.2.0</td></tr><tr><td>1.3.x</td><td>1.5.2</td></tr></tbody></table><p>Spring Boot、Spring Data Elasticsearch、Elasticsearch 对应版本</p><table><thead><tr><th align="center">Spring Data Release Train</th><th align="center">Spring Data Elasticsearch</th><th align="center">Elasticsearch</th><th align="center">Spring Boot</th></tr></thead><tbody><tr><td align="center">Neumann[<a href="https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#_footnotedef_1" target="_blank" rel="noopener">1</a>]</td><td align="center">4.0.x[<a href="https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#_footnotedef_1" target="_blank" rel="noopener">1</a>]</td><td align="center">7.6.2</td><td align="center">2.3.x[<a href="https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#_footnotedef_1" target="_blank" rel="noopener">1</a>]</td></tr><tr><td align="center">Moore</td><td align="center">3.2.x</td><td align="center">6.8.6</td><td align="center">2.2.x</td></tr><tr><td align="center">Lovelace</td><td align="center">3.1.x</td><td align="center">6.2.2</td><td align="center">2.1.x</td></tr><tr><td align="center">Kay[<a href="https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#_footnotedef_2" target="_blank" rel="noopener">2</a>]</td><td align="center">3.0.x[<a href="https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#_footnotedef_2" target="_blank" rel="noopener">2</a>]</td><td align="center">5.5.0</td><td align="center">2.0.x[<a href="https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#_footnotedef_2" target="_blank" rel="noopener">2</a>]</td></tr><tr><td align="center">Ingalls[<a href="https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#_footnotedef_2" target="_blank" rel="noopener">2</a>]</td><td align="center">2.1.x[<a href="https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#_footnotedef_2" target="_blank" rel="noopener">2</a>]</td><td align="center">2.4.0</td><td align="center">1.5.x[<a href="https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#_footnotedef_2" target="_blank" rel="noopener">2</a>]</td></tr></tbody></table><p>dome参考：<a href="https://github.com/spring-projects/spring-data-examples/tree/master/elasticsearch" target="_blank" rel="noopener">https://github.com/spring-projects/spring-data-examples/tree/master/elasticsearch</a></p><h4 id="Java-Elasticsearch-客户端"><a href="#Java-Elasticsearch-客户端" class="headerlink" title="Java Elasticsearch 客户端"></a>Java Elasticsearch 客户端</h4><p>官方推荐：<a href="https://www.elastic.co/guide/en/elasticsearch/client/index.html" target="_blank" rel="noopener">https://www.elastic.co/guide/en/elasticsearch/client/index.html</a></p><ul><li><strong>Transport Client</strong> 不推荐</li><li><strong><a href="https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.8/java-rest-high.html" target="_blank" rel="noopener">Java High Level REST Client</a></strong> 推荐</li><li><strong>Reactive REST Client</strong> 不推荐</li></ul><h2 id="二、Spring-Data-Elasticsearch"><a href="#二、Spring-Data-Elasticsearch" class="headerlink" title="二、Spring Data Elasticsearch"></a>二、Spring Data Elasticsearch</h2><blockquote><p>Spring Data Elasticsearch 默认使用 High Level REST Client</p><p>版本：springboot 2.0.5、Elasticsearch6.8.5、springboot data elasticsearch3.2.5</p></blockquote><p>pom.xml</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.data<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-data-elasticsearch<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>3.2.5.RELEASE<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.elasticsearch<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>elasticsearch<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>6.8.5<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure><p>*.yml</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">data:</span></span><br><span class="line">    <span class="attr">elasticsearch:</span></span><br><span class="line">      <span class="attr">repositories:</span></span><br><span class="line">        <span class="attr">enabled:</span> <span class="literal">true</span> <span class="comment"># 启用 ElasticsearchTemplate</span></span><br><span class="line">      <span class="attr">properties:</span></span><br><span class="line">        <span class="attr">path:</span></span><br><span class="line">          <span class="attr">logs:</span> <span class="string">./elasticsearch/log</span>   <span class="comment"># ES日志存储目录</span></span><br><span class="line">          <span class="attr">data:</span> <span class="string">./elasticsearch/data</span>  <span class="comment"># ES数据存储目录</span></span><br><span class="line">      <span class="attr">cluster-name:</span> <span class="string">my-cluster</span>        <span class="comment"># ES集群名称，在elasticsearch.yml中配置 默 elasticsearch</span></span><br><span class="line">      <span class="attr">cluster-nodes:</span> <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span><span class="string">:9300</span>   <span class="comment"># ES集群节点 用逗号分隔 , java连接默9300，http连接默9200</span></span><br></pre></td></tr></table></figure><p>实体类</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="meta">@Document</span>(indexName = <span class="string">"book_index"</span>, type = <span class="string">"book_type"</span>, indexStoreType = <span class="string">"fs"</span>, shards = <span class="number">5</span>, replicas = <span class="number">1</span>, refreshInterval = <span class="string">"-1"</span>)</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">BookEntity</span> </span>&#123;</span><br><span class="line">    <span class="meta">@Id</span></span><br><span class="line">    <span class="keyword">private</span> String id;</span><br><span class="line">    <span class="keyword">private</span> String title;</span><br><span class="line">    <span class="keyword">private</span> String content;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">int</span> userId;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">int</span> weight;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>Repository接口</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">BookRepository</span> <span class="keyword">extends</span> <span class="title">ElasticsearchRepository</span>&lt;<span class="title">BookEntity</span>, <span class="title">String</span>&gt; </span>&#123;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>controller层</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.dist.controller;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.dist.dao.BookRepository;</span><br><span class="line"><span class="keyword">import</span> com.dist.entity.BookEntity;</span><br><span class="line"><span class="keyword">import</span> io.swagger.annotations.Api;</span><br><span class="line"><span class="keyword">import</span> io.swagger.annotations.ApiOperation;</span><br><span class="line"><span class="keyword">import</span> io.swagger.annotations.ApiParam;</span><br><span class="line"><span class="keyword">import</span> org.elasticsearch.index.query.MultiMatchQueryBuilder;</span><br><span class="line"><span class="keyword">import</span> org.elasticsearch.index.query.QueryBuilders;</span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line"><span class="keyword">import</span> org.springframework.data.domain.PageRequest;</span><br><span class="line"><span class="keyword">import</span> org.springframework.data.elasticsearch.core.ElasticsearchTemplate;</span><br><span class="line"><span class="keyword">import</span> org.springframework.data.elasticsearch.core.query.IndexQuery;</span><br><span class="line"><span class="keyword">import</span> org.springframework.data.elasticsearch.core.query.IndexQueryBuilder;</span><br><span class="line"><span class="keyword">import</span> org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;</span><br><span class="line"><span class="keyword">import</span> org.springframework.data.elasticsearch.core.query.SearchQuery;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.*;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="keyword">static</span> org.elasticsearch.index.query.QueryBuilders.*;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> zhengja@dist.com.cn</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@data</span> 2020/07/17 11:41</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="meta">@Api</span>(tags = &#123;<span class="string">"BookElasticsearchController"</span>&#125;, description = <span class="string">"全文检索"</span>)</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">BookElasticsearchController</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    ElasticsearchTemplate elasticsearchTemplate;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    BookRepository bookRepository;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"添加索引"</span>, httpMethod = <span class="string">"POST"</span>)</span><br><span class="line">    <span class="meta">@PostMapping</span>(value = <span class="string">"v1/book/add/&#123;id&#125;"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Object <span class="title">addbook</span><span class="params">(@ApiParam(defaultValue = <span class="string">"50"</span>)</span> @PathVariable String id) </span>&#123;</span><br><span class="line">        <span class="comment">//创建索引</span></span><br><span class="line">        <span class="comment">// 1、直接用名称创建索引</span></span><br><span class="line">        <span class="comment">//boolean indexRes = elasticsearchTemplate.createIndex("book_es");</span></span><br><span class="line">        <span class="comment">// 2、填入class对象创建索引</span></span><br><span class="line">        <span class="comment">//boolean indexRes = elasticsearchTemplate.createIndex(BookEntity.class);</span></span><br><span class="line">        <span class="comment">//System.out.println("======创建索引结果：" + indexRes + "=========");</span></span><br><span class="line"></span><br><span class="line">        BookEntity bookEntity = <span class="keyword">new</span> BookEntity();</span><br><span class="line">        bookEntity.setId(id);</span><br><span class="line">        bookEntity.setTitle(<span class="string">"浣溪沙"</span>);</span><br><span class="line">        bookEntity.setContent(<span class="string">"宋·李清照 莫许杯深琥珀浓，未成沉醉意先融。疏钟已应晚来风。瑞脑香消魂梦断"</span>);</span><br><span class="line">        bookEntity.setUserId(<span class="number">51</span>);</span><br><span class="line">        bookEntity.setWeight(<span class="number">100</span>);</span><br><span class="line"></span><br><span class="line">        IndexQuery indexQuery = <span class="keyword">new</span> IndexQueryBuilder()</span><br><span class="line">                .withId(bookEntity.getId())</span><br><span class="line">                .withObject(bookEntity)</span><br><span class="line">                .build();</span><br><span class="line">        String index = elasticsearchTemplate.index(indexQuery);</span><br><span class="line">        <span class="comment">//BookEntity document = bookRepository.save(bookEntity);</span></span><br><span class="line">        <span class="keyword">return</span> index;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"查询全部内容"</span>, httpMethod = <span class="string">"GET"</span>)</span><br><span class="line">    <span class="meta">@GetMapping</span>(value = <span class="string">"v1/book/srarch/all"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Object <span class="title">srarch</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> bookRepository.findAll();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"根据id查询内容"</span>, httpMethod = <span class="string">"GET"</span>)</span><br><span class="line">    <span class="meta">@GetMapping</span>(value = <span class="string">"v1/book/srarch/id"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Object <span class="title">srarch</span><span class="params">(@ApiParam(defaultValue = <span class="string">"50"</span>)</span> @RequestParam String id) </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> bookRepository.findById(id);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"根据id更新内容"</span>, httpMethod = <span class="string">"PUT"</span>)</span><br><span class="line">    <span class="meta">@PutMapping</span>(value = <span class="string">"v1/book/srarch/updete"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Object <span class="title">updete</span><span class="params">(@ApiParam(defaultValue = <span class="string">"50"</span>)</span> @RequestParam String id) </span>&#123;</span><br><span class="line">        BookEntity bookEntity = <span class="keyword">new</span> BookEntity();</span><br><span class="line">        bookEntity.setId(id);</span><br><span class="line">        bookEntity.setTitle(<span class="string">"浣溪沙2"</span>);</span><br><span class="line">        bookEntity.setContent(<span class="string">"宋·李清照 莫许杯深琥珀浓，未成沉醉意先融。疏钟已应晚来风。瑞脑香消魂梦断"</span>);</span><br><span class="line">        bookEntity.setUserId(<span class="number">55</span>);</span><br><span class="line">        bookEntity.setWeight(<span class="number">102</span>);</span><br><span class="line">        <span class="keyword">return</span> bookRepository.save(bookEntity);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"单字符串全文模糊查询Ex"</span>, httpMethod = <span class="string">"GET"</span>)</span><br><span class="line">    <span class="meta">@GetMapping</span>(value = <span class="string">"v1/book/srarch/ex"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Object <span class="title">srarchEx</span><span class="params">(@ApiParam(value = <span class="string">"查询内容"</span>, defaultValue = <span class="string">"浣溪沙"</span>)</span> @RequestParam String content,</span></span><br><span class="line"><span class="function">                         @<span class="title">ApiParam</span><span class="params">(value = <span class="string">"当前页"</span>, defaultValue = <span class="string">"0"</span>)</span> @RequestParam <span class="keyword">int</span> page,</span></span><br><span class="line"><span class="function">                         @<span class="title">ApiParam</span><span class="params">(value = <span class="string">"显示多少条"</span>, defaultValue = <span class="string">"20"</span>)</span> @RequestParam <span class="keyword">int</span> size) </span>&#123;</span><br><span class="line"></span><br><span class="line">        SearchQuery searchQuery = <span class="keyword">new</span> NativeSearchQueryBuilder().withQuery(QueryBuilders.queryStringQuery(content)).withPageable(PageRequest.of(page, size)).build();</span><br><span class="line">        <span class="keyword">return</span> bookRepository.search(searchQuery);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"多字段的匹配查询Ex"</span>, httpMethod = <span class="string">"GET"</span>)</span><br><span class="line">    <span class="meta">@GetMapping</span>(value = <span class="string">"v1/book/srarch/queryBuilder"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Object <span class="title">srarchQueryBuilder</span><span class="params">(@ApiParam(value = <span class="string">"查询内容"</span>, defaultValue = <span class="string">"浣溪沙"</span>)</span> @RequestParam String title) </span>&#123;</span><br><span class="line"></span><br><span class="line">        MultiMatchQueryBuilder queryBuilder = multiMatchQuery(title, <span class="string">"title"</span>, <span class="string">"content"</span>);</span><br><span class="line">        <span class="keyword">return</span> bookRepository.search(queryBuilder);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"单字符串全文模糊查询"</span>, notes = <span class="string">"查询全部字段内容"</span>, httpMethod = <span class="string">"GET"</span>)</span><br><span class="line">    <span class="meta">@GetMapping</span>(value = <span class="string">"v1/book/srarch"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Object <span class="title">srarch</span><span class="params">(@ApiParam(value = <span class="string">"查询内容"</span>, defaultValue = <span class="string">"浣溪沙"</span>)</span> @RequestParam String content,</span></span><br><span class="line"><span class="function">                         @<span class="title">ApiParam</span><span class="params">(value = <span class="string">"当前页"</span>, defaultValue = <span class="string">"0"</span>)</span> @RequestParam <span class="keyword">int</span> page,</span></span><br><span class="line"><span class="function">                         @<span class="title">ApiParam</span><span class="params">(value = <span class="string">"显示多少条"</span>, defaultValue = <span class="string">"20"</span>)</span> @RequestParam <span class="keyword">int</span> size) </span>&#123;</span><br><span class="line">        <span class="comment">//使用queryStringQuery完成单字符串查询</span></span><br><span class="line">        <span class="comment">//单字符串默认模糊查询，默认排序。将从所有字段中查找包含传来的content分词后字符串的数据集</span></span><br><span class="line">        SearchQuery searchQuery = <span class="keyword">new</span> NativeSearchQueryBuilder().withQuery(QueryBuilders.queryStringQuery(content)).withPageable(PageRequest.of(page, size)).build();</span><br><span class="line">        <span class="keyword">return</span> elasticsearchTemplate.queryForList(searchQuery, BookEntity<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"某字段字符串模糊查询"</span>, notes = <span class="string">"将从所有字段中查找包含传来的content分词后字符串的数据集"</span>, httpMethod = <span class="string">"GET"</span>)</span><br><span class="line">    <span class="meta">@GetMapping</span>(value = <span class="string">"v1/book/srarch/matchQuery"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Object <span class="title">srarchMatchQuery</span><span class="params">(@ApiParam(value = <span class="string">"查询内容"</span>, defaultValue = <span class="string">"浣溪沙"</span>)</span> @RequestParam String content,</span></span><br><span class="line"><span class="function">                                   @<span class="title">ApiParam</span><span class="params">(value = <span class="string">"当前页"</span>, defaultValue = <span class="string">"0"</span>)</span> @RequestParam <span class="keyword">int</span> page,</span></span><br><span class="line"><span class="function">                                   @<span class="title">ApiParam</span><span class="params">(value = <span class="string">"显示多少条"</span>, defaultValue = <span class="string">"20"</span>)</span> @RequestParam <span class="keyword">int</span> size) </span>&#123;</span><br><span class="line">        <span class="comment">//某字段(content)字符串模糊查询</span></span><br><span class="line">        SearchQuery searchQuery = <span class="keyword">new</span> NativeSearchQueryBuilder().withQuery(matchQuery(<span class="string">"content"</span>, content)).withPageable(PageRequest.of(page, size)).build();</span><br><span class="line">        <span class="keyword">return</span> elasticsearchTemplate.queryForList(searchQuery, BookEntity<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"短语匹配"</span>, notes = <span class="string">"短语必须是连续的 不知归路 不归路"</span>, httpMethod = <span class="string">"GET"</span>)</span><br><span class="line">    <span class="meta">@GetMapping</span>(value = <span class="string">"v1/book/srarch/PhraseQuery"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Object <span class="title">srarchPhraseQuery</span><span class="params">(@ApiParam(<span class="string">"查询内容"</span>)</span> @RequestParam String content,</span></span><br><span class="line"><span class="function">                                    @<span class="title">ApiParam</span><span class="params">(value = <span class="string">"当前页"</span>, defaultValue = <span class="string">"0"</span>)</span> @RequestParam <span class="keyword">int</span> page,</span></span><br><span class="line"><span class="function">                                    @<span class="title">ApiParam</span><span class="params">(value = <span class="string">"显示多少条"</span>, defaultValue = <span class="string">"20"</span>)</span> @RequestParam <span class="keyword">int</span> size) </span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// PhraseMatch查询，短语匹配，单字段对某短语进行匹配查询，短语分词的顺序会影响结果</span></span><br><span class="line">        <span class="comment">//类似于数据库里的 %落日熔金%</span></span><br><span class="line">        SearchQuery searchQuery = <span class="keyword">new</span> NativeSearchQueryBuilder().withQuery(QueryBuilders.matchPhraseQuery(<span class="string">"content"</span>, content)).withPageable(PageRequest.of(page, size)).build();</span><br><span class="line">        <span class="keyword">return</span> elasticsearchTemplate.queryForList(searchQuery, BookEntity<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"完全匹配查询"</span>, notes = <span class="string">"最严格的匹配,不进行分词"</span>, httpMethod = <span class="string">"GET"</span>)</span><br><span class="line">    <span class="meta">@GetMapping</span>(value = <span class="string">"v1/book/srarch/TermQuery"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Object <span class="title">srarchTermQuery</span><span class="params">(@ApiParam(value = <span class="string">"id"</span>, defaultValue = <span class="string">"5"</span>)</span> @RequestParam <span class="keyword">int</span> userId,</span></span><br><span class="line"><span class="function">                                  @<span class="title">ApiParam</span><span class="params">(value = <span class="string">"当前页"</span>, defaultValue = <span class="string">"0"</span>)</span> @RequestParam <span class="keyword">int</span> page,</span></span><br><span class="line"><span class="function">                                  @<span class="title">ApiParam</span><span class="params">(value = <span class="string">"显示多少条"</span>, defaultValue = <span class="string">"10"</span>)</span> @RequestParam <span class="keyword">int</span> size) </span>&#123;</span><br><span class="line">        <span class="comment">//term一般适用于做过滤器filter的情况，譬如我们去查询title中包含“浣溪沙”且userId=1时，那么就可以用termQuery(“userId”, 1)作为查询的filter</span></span><br><span class="line">        <span class="comment">//不对传来的值分词，去找完全匹配的</span></span><br><span class="line">        SearchQuery searchQuery = <span class="keyword">new</span> NativeSearchQueryBuilder().withQuery(termQuery(<span class="string">"userId"</span>, userId)).withPageable(PageRequest.of(page, size)).build();</span><br><span class="line">        <span class="keyword">return</span> elasticsearchTemplate.queryForList(searchQuery, BookEntity<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"多字段的匹配查询"</span>, httpMethod = <span class="string">"GET"</span>)</span><br><span class="line">    <span class="meta">@GetMapping</span>(value = <span class="string">"v1/book/srarch/MultiMatchQuery"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Object <span class="title">srarchMultiMatchQuery</span><span class="params">(@ApiParam(<span class="string">"查询内容"</span>)</span> @RequestParam String title,</span></span><br><span class="line"><span class="function">                                        @<span class="title">ApiParam</span><span class="params">(value = <span class="string">"当前页"</span>, defaultValue = <span class="string">"0"</span>)</span> @RequestParam <span class="keyword">int</span> page,</span></span><br><span class="line"><span class="function">                                        @<span class="title">ApiParam</span><span class="params">(value = <span class="string">"显示多少条"</span>, defaultValue = <span class="string">"10"</span>)</span> @RequestParam <span class="keyword">int</span> size) </span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//MultiMatchQuery: 多字段匹配 "title","content" ,只要任何一个字段包括该字符串即可</span></span><br><span class="line">        SearchQuery searchQuery = <span class="keyword">new</span> NativeSearchQueryBuilder()</span><br><span class="line">                .withQuery(QueryBuilders.multiMatchQuery(title, <span class="string">"title"</span>, <span class="string">"content"</span>))</span><br><span class="line">                .withPageable(PageRequest.of(page, size))</span><br><span class="line">                .build();</span><br><span class="line"></span><br><span class="line">        <span class="comment">//MultiMatchQueryBuilder multiMatchQuery = QueryBuilders.multiMatchQuery(title, "title", "content");</span></span><br><span class="line">        <span class="comment">//构建查询对象</span></span><br><span class="line">        <span class="comment">/*SearchQuery searchQuery = new NativeSearchQueryBuilder()</span></span><br><span class="line"><span class="comment">                .withQuery(multiMatchQuery)</span></span><br><span class="line"><span class="comment">                .withIndices("book_es")  //索引名</span></span><br><span class="line"><span class="comment">                .withPageable(PageRequest.of(page, size, new Sort(Sort.Direction.DESC, "id")))</span></span><br><span class="line"><span class="comment">                .build();*/</span></span><br><span class="line">        <span class="comment">//执行查询</span></span><br><span class="line">        <span class="keyword">return</span> elasticsearchTemplate.queryForList(searchQuery, BookEntity<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"多字段合并查询"</span>, httpMethod = <span class="string">"GET"</span>)</span><br><span class="line">    <span class="meta">@GetMapping</span>(value = <span class="string">"v1/book/srarch/BoolQuery"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Object <span class="title">srarchBoolQuery</span><span class="params">(@ApiParam(value = <span class="string">"userId"</span>, defaultValue = <span class="string">"2"</span>)</span> @RequestParam String userId,</span></span><br><span class="line"><span class="function">                                  @<span class="title">ApiParam</span><span class="params">(value = <span class="string">"weight"</span>, defaultValue = <span class="string">"14"</span>)</span> @RequestParam String weight,</span></span><br><span class="line"><span class="function">                                  @<span class="title">ApiParam</span><span class="params">(value = <span class="string">"title"</span>, defaultValue = <span class="string">"浣溪沙"</span>)</span> @RequestParam String title) </span>&#123;</span><br><span class="line">        <span class="comment">//boolQuery 可以设置多个条件的查询方式,用来组合多个Query,组合方式有四种：must，mustnot，filter，should</span></span><br><span class="line">        <span class="comment">/*must代表返回的文档必须满足must子句的条件，会参与计算分值；</span></span><br><span class="line"><span class="comment">        filter代表返回的文档必须满足filter子句的条件，但不会参与计算分值；</span></span><br><span class="line"><span class="comment">        should代表返回的文档可能满足should子句的条件，也可能不满足，有多个should时满足任何一个就可以，通过minimum_should_match设置至少满足几个。</span></span><br><span class="line"><span class="comment">        mustnot代表必须不满足子句的条件。*/</span></span><br><span class="line">        SearchQuery searchQuery = <span class="keyword">new</span> NativeSearchQueryBuilder().withQuery(QueryBuilders.boolQuery().must(termQuery(<span class="string">"userId"</span>, userId))</span><br><span class="line">                .should(rangeQuery(<span class="string">"weight"</span>).lt(weight)).must(matchQuery(<span class="string">"title"</span>, title))).build();</span><br><span class="line">        <span class="keyword">return</span> elasticsearchTemplate.queryForList(searchQuery, BookEntity<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"删除索引"</span>, httpMethod = <span class="string">"DELETE"</span>)</span><br><span class="line">    <span class="meta">@DeleteMapping</span>(value = <span class="string">"v1/book/delete"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">deleteIndex</span><span class="params">(@ApiParam(<span class="string">"id"</span>)</span> @RequestParam String id) </span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//删除索引</span></span><br><span class="line">        BookEntity bookEntity = <span class="keyword">new</span> BookEntity();</span><br><span class="line">        bookEntity.setId(id);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//bookRepository.delete(bookEntity);</span></span><br><span class="line">        <span class="comment">//根据id删除</span></span><br><span class="line">        bookRepository.deleteById(id);</span><br><span class="line">        <span class="comment">//删除所有</span></span><br><span class="line">        <span class="comment">//bookRepository.deleteAll();</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"删除所有索引"</span>, httpMethod = <span class="string">"DELETE"</span>)</span><br><span class="line">    <span class="meta">@DeleteMapping</span>(value = <span class="string">"v1/book/delete/all"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">deleteAllIndex</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="comment">//删除所有</span></span><br><span class="line">        bookRepository.deleteAll();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>InitBookData 初始化数据</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * Email: zhengja@dist.com.cn</span></span><br><span class="line"><span class="comment"> * Desc：只初始化一次测试数据</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">InitBookData</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    BookRepository bookRepository;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@PostConstruct</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">init</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="comment">//只初始化一次</span></span><br><span class="line">        Iterable&lt;BookEntity&gt; posts = bookRepository.findAll();</span><br><span class="line">        <span class="keyword">if</span> (posts.iterator().hasNext()) &#123;</span><br><span class="line">            <span class="keyword">return</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">40</span>; i++) &#123;</span><br><span class="line">            BookEntity book = <span class="keyword">new</span> BookEntity();</span><br><span class="line">            book.setTitle(getTitle().get(i));</span><br><span class="line">            book.setContent(getContent().get(i));</span><br><span class="line">            book.setWeight(i);</span><br><span class="line">            book.setUserId(i % <span class="number">10</span>);</span><br><span class="line">            bookRepository.save(book);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> List&lt;String&gt; <span class="title">getTitle</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        List&lt;String&gt; list = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        list.add(<span class="string">"《如梦令·常记溪亭日暮》"</span>);</span><br><span class="line">        list.add(<span class="string">"《醉花阴·薄雾浓云愁永昼》"</span>);</span><br><span class="line">        list.add(<span class="string">"《声声慢·寻寻觅觅》"</span>);</span><br><span class="line">        list.add(<span class="string">"《永遇乐·落日熔金》"</span>);</span><br><span class="line">        list.add(<span class="string">"《如梦令·昨夜雨疏风骤》"</span>);</span><br><span class="line">        list.add(<span class="string">"《渔家傲·雪里已知春信至》"</span>);</span><br><span class="line">        list.add(<span class="string">"《点绛唇·蹴[1]罢秋千》"</span>);</span><br><span class="line">        list.add(<span class="string">"《点绛唇·寂寞深闺》"</span>);</span><br><span class="line">        list.add(<span class="string">"《蝶恋花·泪湿罗衣脂粉满》"</span>);</span><br><span class="line">        list.add(<span class="string">"《蝶恋花 离情》"</span>);</span><br><span class="line">        list.add(<span class="string">"《浣溪沙》"</span>);</span><br><span class="line">        list.add(<span class="string">"《浣溪沙》"</span>);</span><br><span class="line">        list.add(<span class="string">"《浣溪沙》"</span>);</span><br><span class="line">        list.add(<span class="string">"《浣溪沙》"</span>);</span><br><span class="line">        list.add(<span class="string">"《浣溪沙》"</span>);</span><br><span class="line">        list.add(<span class="string">"《减字木兰花·卖花担上》"</span>);</span><br><span class="line">        list.add(<span class="string">"《临江仙·欧阳公作《蝶恋花》"</span>);</span><br><span class="line">        list.add(<span class="string">"《临江仙·庭院深深深几许》"</span>);</span><br><span class="line">        list.add(<span class="string">"《念奴娇·萧条庭院》"</span>);</span><br><span class="line">        list.add(<span class="string">"《菩萨蛮·风柔日薄春犹早》"</span>);</span><br><span class="line">        list.add(<span class="string">"《菩萨蛮·归鸿声断残云碧》"</span>);</span><br><span class="line">        list.add(<span class="string">"《武陵春·风住尘香花已尽》"</span>);</span><br><span class="line">        list.add(<span class="string">"《一剪梅·红藕香残玉蕈秋》"</span>);</span><br><span class="line">        list.add(<span class="string">"《渔家傲·天接云涛连晓雾》"</span>);</span><br><span class="line">        list.add(<span class="string">"《鹧鸪天·暗淡轻黄体性柔》"</span>);</span><br><span class="line">        list.add(<span class="string">"《鹧鸪天·寒日萧萧上锁窗》"</span>);</span><br><span class="line">        list.add(<span class="string">"《一剪梅·红藕香残玉簟秋》"</span>);</span><br><span class="line">        list.add(<span class="string">"《如梦令·常记溪亭日暮》"</span>);</span><br><span class="line">        list.add(<span class="string">"《浣溪沙》"</span>);</span><br><span class="line">        list.add(<span class="string">"《浣溪沙》"</span>);</span><br><span class="line">        list.add(<span class="string">"《浣溪沙》"</span>);</span><br><span class="line">        list.add(<span class="string">"《蝶恋花·泪湿罗衣脂粉满》"</span>);</span><br><span class="line">        list.add(<span class="string">"《蝶恋花·暖日晴风初破冻》"</span>);</span><br><span class="line">        list.add(<span class="string">"《鹧鸪天·寒日萧萧上锁窗》"</span>);</span><br><span class="line">        list.add(<span class="string">"《醉花阴·薄雾浓云愁永昼》"</span>);</span><br><span class="line">        list.add(<span class="string">"《鹧鸪天·暗淡轻黄体性柔》"</span>);</span><br><span class="line">        list.add(<span class="string">"《蝶恋花·永夜恹恹欢意少》"</span>);</span><br><span class="line">        list.add(<span class="string">"《浣溪沙》"</span>);</span><br><span class="line">        list.add(<span class="string">"《浣溪沙》"</span>);</span><br><span class="line">        list.add(<span class="string">"《如梦令·谁伴明窗独坐》"</span>);</span><br><span class="line">        <span class="keyword">return</span> list;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> List&lt;String&gt; <span class="title">getContent</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        List&lt;String&gt; list = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        list.add(<span class="string">"初中 宋·李清照 常记溪亭日暮，沉醉不知归路，兴尽晚回舟，误入藕花深处。争渡，争渡"</span>);</span><br><span class="line">        list.add(<span class="string">"重阳节 宋·李清照 薄雾浓云愁永昼，瑞脑消金兽。佳节又重阳，玉枕纱厨，半夜凉初透。东"</span>);</span><br><span class="line">        list.add(<span class="string">"闺怨诗 宋·李清照 寻寻觅觅，冷冷清清，凄凄惨惨戚戚。乍暖还寒时候，最难将息。三杯两"</span>);</span><br><span class="line">        list.add(<span class="string">"元宵节 宋·李清照 落日熔金，暮云合璧，人在何处。染柳烟浓，吹梅笛怨，春意知几许。元"</span>);</span><br><span class="line">        list.add(<span class="string">"婉约诗 宋·李清照 昨夜雨疏风骤，浓睡不消残酒，试问卷帘人，却道海棠依旧。知否，知否"</span>);</span><br><span class="line">        list.add(<span class="string">"描写梅花 宋·李清照 雪里已知春信至，寒梅点缀琼枝腻，香脸半开娇旖旎，当庭际，玉人浴出"</span>);</span><br><span class="line">        list.add(<span class="string">" 宋·李清照 蹴罢秋千，起来慵整纤纤手。露浓花瘦，薄汗轻衣透。见客入来，袜刬金"</span>);</span><br><span class="line">        list.add(<span class="string">"闺怨诗 宋·李清照 寂寞深闺，柔肠一寸愁千缕。惜春春去。几点催花雨。倚遍阑干，只是无"</span>);</span><br><span class="line">        list.add(<span class="string">"婉约诗 宋·李清照 泪湿罗衣脂粉满。四叠阳关，唱到千千遍。人道山长水又断。萧萧微雨闻"</span>);</span><br><span class="line">        list.add(<span class="string">"描写春天 宋·李清照 暖雨晴风初破冻，柳眼梅腮，已觉春心动。酒意诗情谁与共？泪融残粉花"</span>);</span><br><span class="line">        list.add(<span class="string">"寒食节 宋·李清照 淡荡春光寒食天，玉炉沈水袅残烟，梦回山枕隐花钿。海燕未来人斗草，"</span>);</span><br><span class="line">        list.add(<span class="string">" 宋·李清照 髻子伤春慵更梳，晚风庭院落梅初，淡云来往月疏疏，玉鸭薰炉闲瑞脑，"</span>);</span><br><span class="line">        list.add(<span class="string">" 宋·李清照 莫许杯深琥珀浓，未成沉醉意先融。疏钟已应晚来风。瑞脑香消魂梦断，"</span>);</span><br><span class="line">        list.add(<span class="string">"闺怨诗 宋·李清照 小院闲窗春已深，重帘未卷影沉沉。倚楼无语理瑶琴，远岫出山催薄暮。"</span>);</span><br><span class="line">        list.add(<span class="string">"爱情诗 宋·李清照 绣幕芙蓉一笑开，斜偎宝鸭亲香腮，眼波才动被人猜。一面风情深有韵，"</span>);</span><br><span class="line">        list.add(<span class="string">"描写春天 宋·李清照 卖花担上，买得一枝春欲放。泪染轻匀，犹带彤霞晓露痕。怕郎猜道，奴"</span>);</span><br><span class="line">        list.add(<span class="string">"》 宋·李清照 欧阳公作《蝶恋花》，有“深深深几许”之句，予酷爱之。用其语作“庭"</span>);</span><br><span class="line">        list.add(<span class="string">"描写梅花 宋·李清照 庭院深深深几许，云窗雾阁春迟，为谁憔悴损芳姿。夜来清梦好，应是发"</span>);</span><br><span class="line">        list.add(<span class="string">"寒食节 宋·李清照 萧条庭院，又斜风细雨，重门须闭。宠柳娇花寒食近，种种恼人天气。险"</span>);</span><br><span class="line">        list.add(<span class="string">"思乡诗 宋·李清照 风柔日薄春犹早，夹衫乍著心情好。睡起觉微寒，梅花鬓上残。故乡何处"</span>);</span><br><span class="line">        list.add(<span class="string">"描写春天 宋·李清照 归鸿声断残云碧，背窗雪落炉烟直。烛底凤钗明，钗头人胜轻。角声催晓"</span>);</span><br><span class="line">        list.add(<span class="string">"闺怨诗 宋·李清照 风住尘香花已尽，日晚倦梳头。物是人非事事休，欲语泪先流。闻说双溪"</span>);</span><br><span class="line">        list.add(<span class="string">" 宋·李清照 红藕香残玉蕈秋，轻解罗裳，独上兰舟。云中谁寄锦书来？雁字回时，月"</span>);</span><br><span class="line">        list.add(<span class="string">"豪放诗 宋·李清照 天接云涛连晓雾。星河欲转千帆舞。仿佛梦魂归帝所。闻天语。殷勤问我"</span>);</span><br><span class="line">        list.add(<span class="string">"描写花 宋·李清照 暗淡轻黄体性柔。情疏迹远只香留。何须浅碧深红色，自是花中第一流。"</span>);</span><br><span class="line">        list.add(<span class="string">"描写秋天 宋·李清照 寒日萧萧上琐窗，梧桐应恨夜来霜。酒阑更喜团茶苦，梦断偏宜瑞脑香。"</span>);</span><br><span class="line">        list.add(<span class="string">"闺怨诗 宋·李清照 红藕香残玉簟秋。轻解罗裳，独上兰舟。云中谁寄锦书来？雁字回时，月"</span>);</span><br><span class="line">        list.add(<span class="string">" 宋·李清照 常记溪亭日暮。沈醉不知归路。兴尽晚回舟，误入藕花深处。争渡。争渡"</span>);</span><br><span class="line">        list.add(<span class="string">" 宋·李清照 莫许杯深琥珀浓。未成沈醉意先融。已应晚来风。瑞脑香消魂梦断，"</span>);</span><br><span class="line">        list.add(<span class="string">" 宋·李清照 小院闲窗春色深。重帘未卷影沈沈。倚楼无语理瑶琴。远岫出山催薄暮，"</span>);</span><br><span class="line">        list.add(<span class="string">" 宋·李清照 淡荡春光寒食天。玉炉沈水袅残烟。梦回山枕隐花钿。海燕未来人斗草，"</span>);</span><br><span class="line">        list.add(<span class="string">" 宋·李清照 泪湿罗衣脂粉满。四叠阳关，唱到千千遍。人道山长山又断。萧萧微雨闻"</span>);</span><br><span class="line">        list.add(<span class="string">" 宋·李清照 暖日晴风初破冻。柳眼眉腮，已觉春心动。酒意诗情谁与共。泪融残粉花"</span>);</span><br><span class="line">        list.add(<span class="string">" 宋·李清照 寒日萧萧上锁窗。梧桐应恨夜来霜。酒阑更喜团茶苦，梦断偏宜瑞脑香。"</span>);</span><br><span class="line">        list.add(<span class="string">" 宋·李清照 薄雾浓云愁永昼。瑞脑消金兽。佳节又重阳，玉枕纱厨，半夜凉初透。东"</span>);</span><br><span class="line">        list.add(<span class="string">" 宋·李清照 暗淡轻黄体性柔。情疏迹远只香留。何须浅碧深红色，自是花中第一流。"</span>);</span><br><span class="line">        list.add(<span class="string">" 宋·李清照 永夜恹恹欢意少。空梦长安，认取长安道。为报今年春色好。花光月影宜"</span>);</span><br><span class="line">        list.add(<span class="string">" 宋·李清照 髻子伤春慵更梳。晚风庭院落梅初。淡云来往月疏疏。玉鸭熏炉闲瑞脑，"</span>);</span><br><span class="line">        list.add(<span class="string">" 宋·李清照 绣面芙蓉一笑开。斜飞宝鸭衬香腮。眼波才动被人猜。一面风情深有韵，"</span>);</span><br><span class="line">        list.add(<span class="string">" 宋·李清照 谁伴明窗独坐，我共影儿俩个。灯尽欲眠时，影也把人抛躲。无那，无那"</span>);</span><br><span class="line">        <span class="keyword">return</span> list;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></div><div><div style="text-align:center;color:#ccc;font-size:14px">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div></div><div class="reward-container"><div><p style="font-size:14px;color:#34495e;margin:0 0 5px 0">赞赏一下吧～ 还可以关注公众号订阅最新内容</p></div><button disable="enable" onclick="var qr = document.getElementById(&quot;qr&quot;); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">打赏</button><div id="qr" style="display:none"><div style="display:inline-block"><img src="/my-images/WeChat.png" alt="宇宙小神特别萌 微信支付"><p>微信支付</p></div><div style="display:inline-block"><img src="/my-images/Alipay.png" alt="宇宙小神特别萌 支付宝"><p>支付宝</p></div></div></div><footer class="post-footer"><div class="post-tags"><a href="/tags/Elasticsearch/" rel="tag"><i class="fa fa-tag"></i> Elasticsearch</a></div><div class="post-nav"><div class="post-nav-item"><a href="/posts/1652353601.html" rel="prev" title="公告"><i class="fa fa-chevron-left"></i> 公告</a></div><div class="post-nav-item"></div></div></footer></article></div></div><div class="comments" id="valine-comments"></div><script>window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }</script></div><div class="toggle sidebar-toggle"><span class="toggle-line toggle-line-first"></span> <span class="toggle-line toggle-line-middle"></span> <span class="toggle-line toggle-line-last"></span></div><aside class="sidebar"><div class="sidebar-inner"><ul class="sidebar-nav motion-element"><li class="sidebar-nav-toc">文章目录</li><li class="sidebar-nav-overview">站点概览</li></ul><div class="post-toc-wrap sidebar-panel"><div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#Elasticsearch-基本介绍"><span class="nav-text">Elasticsearch 基本介绍</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Elasticsearch-6-8-5-单机安装"><span class="nav-text">Elasticsearch 6.8.5 单机安装</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#kibana6-8-5-可视化工具"><span class="nav-text">kibana6.8.5 可视化工具</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#elasticsearch-analysis-ik-分词器"><span class="nav-text">elasticsearch-analysis-ik 分词器</span></a></li></ol><li class="nav-item nav-level-1"><a class="nav-link" href="#Springboot-Elasticsearch-6-8-5"><span class="nav-text">Springboot Elasticsearch 6.8.5</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#一、选择版本"><span class="nav-text">一、选择版本</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#Spring-Data-Elasticsearch"><span class="nav-text">Spring Data Elasticsearch</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Java-Elasticsearch-客户端"><span class="nav-text">Java Elasticsearch 客户端</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二、Spring-Data-Elasticsearch"><span class="nav-text">二、Spring Data Elasticsearch</span></a></li></div></div><div class="site-overview-wrap sidebar-panel"><div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person"><img class="site-author-image" itemprop="image" alt="宇宙小神特别萌" src="/my-images/avatar.gif"><p class="site-author-name" itemprop="name">宇宙小神特别萌</p><div class="site-description" itemprop="description">人生就是一次幸运的旅行！</div></div><div class="site-state-wrap motion-element"><nav class="site-state"><div class="site-state-item site-state-posts"><a href="/archives/"><span class="site-state-item-count">116</span> <span class="site-state-item-name">文章</span></a></div><div class="site-state-item site-state-tags"><a href="/tags/"><span class="site-state-item-count">27</span> <span class="site-state-item-name">标签</span></a></div></nav></div><div class="links-of-author motion-element"><span class="links-of-author-item"><a href="https://github.com/zhengjiaao" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;zhengjiaao" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a> </span><span class="links-of-author-item"><a href="https://www.jianshu.com/u/70d69269bd09" title="简书 → https:&#x2F;&#x2F;www.jianshu.com&#x2F;u&#x2F;70d69269bd09" rel="noopener" target="_blank"><i class="fa fa-fw fa-book"></i>简书</a> </span><span class="links-of-author-item"><a href="/atom.xml" title="RSS → &#x2F;atom.xml"><i class="fa fa-fw fa-rss"></i>RSS</a></span></div><div class="links-of-blogroll motion-element"><div class="links-of-blogroll-title"><i class="fa fa-fw fa-link"></i> 推荐阅读</div><ul class="links-of-blogroll-list"><li class="links-of-blogroll-item"><a href="https://github.com/spring-projects" title="https:&#x2F;&#x2F;github.com&#x2F;spring-projects" rel="noopener" target="_blank">spring-projects</a></li><li class="links-of-blogroll-item"><a href="http://www.alloyteam.com/nav/" title="http:&#x2F;&#x2F;www.alloyteam.com&#x2F;nav&#x2F;" rel="noopener" target="_blank">Web前端导航</a></li><li class="links-of-blogroll-item"><a href="http://www.chuangzaoshi.com/code" title="http:&#x2F;&#x2F;www.chuangzaoshi.com&#x2F;code" rel="noopener" target="_blank">创造狮导航</a></li></ul></div></div></div></aside><div id="sidebar-dimmer"></div></div></main><footer class="footer"><div class="footer-inner"><div class="copyright">&copy; <span itemprop="copyrightYear">2020</span> <span class="with-love"><i class="fa fa-heart"></i> </span><span class="author" itemprop="copyrightHolder">宇宙小神特别萌</span> <span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-area-chart"></i> </span><span title="站点总字数">1.2m</span> <span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-coffee"></i> </span><span title="站点阅读时长">17:41</span></div><div class="busuanzi-count"><script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span class="post-meta-item" id="busuanzi_container_site_uv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-user"></i> </span><span class="site-uv" title="总访客量"><span id="busuanzi_value_site_uv"></span> </span></span><span class="post-meta-divider">|</span> <span class="post-meta-item" id="busuanzi_container_site_pv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="site-pv" title="总访问量"><span id="busuanzi_value_site_pv"></span></span></span></div></div></footer></div><script src="//cdn.jsdelivr.net/npm/animejs@3.1.0/lib/anime.min.js"></script><script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script><script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script><script src="//cdnjs.cloudflare.com/ajax/libs/velocity/1.2.1/velocity.min.js"></script><script src="//cdnjs.cloudflare.com/ajax/libs/velocity/1.2.1/velocity.ui.min.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script><script src="/js/bookmark.js"></script><script>!function(){var t=document.createElement("script"),e=window.location.protocol.split(":")[0];t.src="https"===e?"https://zz.bdstatic.com/linksubmit/push.js":"http://push.zhanzhang.baidu.com/push.js";var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(t,s)}()</script><script src="/js/local-search.js"></script><script>NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//cdnjs.cloudflare.com/ajax/libs/valine/1.3.10/Valine.min.js', () => {
    <!--var GUEST = ['nick', 'mail', 'link'];-->
    var GUEST = ['nick', 'mail'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el: '#valine-comments',
      verify: false,
      notify: false,
      appId: 'OuyHeA0XGL8hK4vgbqL0iERx-gzGzoHsz',
      appKey: 'L58VglKmWULcGK2W2AN7kWzM',
      placeholder: "留下邮箱，有回复时你将收到提醒，邮箱不会被公开。",
      avatar: 'wavatar',
      meta: guest,
      pageSize: '10' || 10,
      visitor: true,
      lang: 'zh-cn' || 'zh-cn',
      path: location.pathname,
      recordIP: true,
      serverURLs: ''
    });
  }, window.Valine);
});</script><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({pluginRootPath:"live2dw/",pluginJsPath:"lib/",pluginModelPath:"assets/",tagMode:!1,model:{jsonPath:"/live2dw/assets/wanko.model.json"},display:{position:"right",width:150,height:300},mobile:{show:!1},log:!1})</script></body><script type="text/javascript" src="/js/src/activetitle.js"></script></html><!-- rebuild by neat -->